package com.solution.service;

import javax.ejb.EJBException;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;

import org.jboss.annotation.ejb.RemoteBinding;

import com.solution.constant.ErrorMessages;
import com.solution.dao.CommunicationTypeDAO;
import com.solution.dao.DAOFactory;
import com.solution.exception.DAOException;
import com.solution.exception.ServiceBeanException;
import com.solution.model.CommunicationType;
import com.solution.util.SearchVO;

@Stateless
@Remote(CommunicationTypeService.class)
@RemoteBinding(jndiBinding="CommunicationTypeService")
@TransactionManagement(TransactionManagementType.CONTAINER)
public class CommunicationTypeServiceImpl implements CommunicationTypeService{
	/**
	 * DAO instance.
	 */
	private CommunicationTypeDAO communicationTypeDao = (CommunicationTypeDAO)DAOFactory.getDAOInstance(CommunicationTypeDAO.class.getName());
	
	public CommunicationType fetchCommunicationTypeByName(String name) throws ServiceBeanException{
		if(name == null || "".equals(name)){
			throw new ServiceBeanException(ErrorMessages.MANDATORY_PARAMETER_MISSING_EXCEPTION+" name");
		}
		else{
			try{
				SearchVO searchVO = new SearchVO();
				searchVO.addEqualsCondition("name", name);
				return communicationTypeDao.searchUnique(searchVO);
			}
			catch(DAOException de){
				throw new EJBException(de);
			}
		}
	}
}
